using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;

namespace JsonRpcGen.TypeHandler
{
    internal class MultiValueHandler : TypeHandler
    {
        private readonly JToken _types;

        public MultiValueHandler(JToken types)
        {
            _types = types;
        }

        public override void Write(StreamWriter writer, string namesp, string className, Dictionary<string, string> replacements)
        {
            EnumTypeHandler.EnumTypes.Add(namesp + "."+ className);
            writer.WriteLine("using System.Runtime.Serialization;" );
            writer.WriteLine("namespace " + namesp);
            writer.WriteLine("{");



            writer.WriteLine("   public enum " + className);
            writer.WriteLine("   {");
            
            foreach (var type in _types)
            {
                switch (type["type"].ToString())
                {
                    case "boolean":
                        
                        writer.WriteLine("   [EnumMember(Value=\"true\")]");
                        writer.WriteLine("   True,");
                        writer.WriteLine("   [EnumMember(Value=\"false\")]");
                        writer.WriteLine("   False,");
                        break;
                    case "string":
                        var vals = type["enums"];
                        foreach (var val in vals)
                        {
                            writer.WriteLine("   " + val.ToString() + ",");    
                        }
                        
                        break;
                    default:
                        throw new NotImplementedException();
                }
            } 
            
            writer.WriteLine("   }");
           
            writer.WriteLine("}");
        }
    }
}